import { NgModule, ErrorHandler } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
import { MyApp } from './app.component';

import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { HttpClientModule, HttpClient } from '@angular/common/http';

import { HttpModule } from "@angular/http";//导入http模块
//国际化组件
import { TranslateModule, TranslateLoader, TranslateService } from '@ngx-translate/core';
//国家化文件加载器
import { TranslateHttpLoader } from "@ngx-translate/http-loader";

import { HTTP } from '@ionic-native/http';
import { AlertsProvider } from '../providers/alerts/alerts';
import { LocateProvider } from '../providers/locate/locate';
import { ToastsProvider } from '../providers/toasts/toasts';
@NgModule({
  declarations: [
    MyApp
  ],
  imports: [ 
    BrowserModule,
    HttpModule,//http网络访问模块
    HttpClientModule,//公共http模块
    TranslateModule.forRoot({
      loader: {
        provide: TranslateLoader,
        useFactory: (createTranslateLoader),
        deps: [HttpClient]
      }
    }),//国际化应用到全局
    IonicModule.forRoot(MyApp)
  ],
  bootstrap: [IonicApp],
  exports: [
    TranslateModule
  ],
  entryComponents: [
    MyApp
  ],
  providers: [
    StatusBar,
    SplashScreen,
    TranslateService,//国家化服务
    HTTP,//网络访问
    { provide: ErrorHandler, useClass: IonicErrorHandler },
    AlertsProvider,
    LocateProvider,
    ToastsProvider

  ]
})
export class AppModule {
  
 }

export function createTranslateLoader(http: HttpClient) {
  return new TranslateHttpLoader(http, 'assets/i18n/', '.json');
}
